package com.object.config;

import cn.dev33.satoken.listener.SaTokenListener;
import cn.dev33.satoken.stp.SaLoginModel;
import com.object.module.lq.sys.service.TOnlineListingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 自定义侦听器的实现
 */
@Component
public class MySaTokenListener implements SaTokenListener
{

    @Autowired
    private TOnlineListingService tOnlineListingService;


    private void OptOutOfOnlineRecords(Object loginId)
    {
//        int userId = Integer.parseInt(loginId.toString());
//        tOnlineListingService.deleteUserId(userId);
    }

    @Override
    public void doLogin(String s, Object o, String s1, SaLoginModel saLoginModel)
    {

    }

    /**
     * 每次注销时触发
     */
    @Override
    public void doLogout(String loginType, Object loginId, String tokenValue)
    {
        // ...
        OptOutOfOnlineRecords(loginId);
    }

    /**
     * 每次被踢下线时触发
     */
    @Override
    public void doKickout(String loginType, Object loginId, String tokenValue)
    {
        // ...
   //     OptOutOfOnlineRecords(loginId);
    }

    /**
     * 每次被顶下线时触发
     */
    @Override
    public void doReplaced(String loginType, Object loginId, String tokenValue)
    {
        // ...
          OptOutOfOnlineRecords(loginId);
    }

    @Override
    public void doDisable(String s, Object o, String s1, int i, long l)
    {
        OptOutOfOnlineRecords(o);
    }

    @Override
    public void doUntieDisable(String s, Object o, String s1)
    {

    }

    @Override
    public void doOpenSafe(String s, String s1, String s2, long l)
    {

    }

    @Override
    public void doCloseSafe(String s, String s1, String s2)
    {

    }

    /**
     * 每次创建Session时触发
     */
    @Override
    public void doCreateSession(String id)
    {
        // ...
    }

    /**
     * 每次注销Session时触发
     */
    @Override
    public void doLogoutSession(String id)
    {
        // ...
        OptOutOfOnlineRecords(id);
    }

    @Override
    public void doRenewTimeout(String s, Object o, long l)
    {

    }

}
